// pages/customer_information/customer_information.js
var App = getApp();
function jsonSort(jsonObj) {
    let arr = [];
    for (var key in jsonObj) {
        arr.push(key)
    }
    arr.sort();
    let str = '';
    for (var i in arr) {
        str += arr[i] + "=" + jsonObj[arr[i]] + "&"
    }
    return str.substr(0, str.length - 1)
}
Page({

    /**
     * 页面的初始数据
     */
    data: {
        many_in: true,//更多信息
        more: '更多信息',
        type: "",//判断潜客还是会员
        id: '',//
        caller: {},//潜客各种信息
        yc: '',
        level: '',//判断是否为经理，控制显示隐藏， 1普通会籍 2会籍主管 3会籍经理
        whereFrom: ['新展', '轮排', '转介绍', '大众点评', '今日头条', '公众号', '电话咨询', '广告', '微信', '公开课', '开放日', '体验卡', '美团'],//来源
        num: "",//维护记录数
        describe: [],//维护记录
        tail_metood: ['默认', '电话跟进', '微信跟进', '面对面跟进', '其他跟进'],//跟进方式
        arrive: [],//是否到店
        yundong: ['0', '腰腹', '减重', '心肺功能提升', '塑性', '体态调整', '疼痛康复', '增加肌肉', '增加力量', '提高柔韧度', '放松压力'],//运动需求与期望效果
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        var This = this;
        This.setData({
            id: options.id,
            type: options.type
        })
        this.loade();
    },
    //更多信息显示隐藏
    many_information: function () {
        var This = this;
        if (This.data.many_in) {
            This.setData({
                many_in: false,
                more: '收起信息'
            })
        } else {
            This.setData({
                many_in: true,
                more: '更多信息'
            })
        }
    },
    //会员卡显示隐藏
    vip_infor: function () {
        var This = this;
        if (This.data.vip) {
            This.setData({
                vip: false,
            })
        } else {
            This.setData({
                vip: true,
            })
        }
    },
    //私教显示隐藏
    sj_information: function () {
        var This = this;
        if (This.data.sj) {
            This.setData({
                sj: false,
            })
        } else {
            This.setData({
                sj: true,
            })
        }
    },
    loade: function () {
        var This = this;
        App._get('caller/callerDetails', {
            store_id: wx.getStorageSync('store_id'),
            openid: wx.getStorageSync('openid'),
            phone: wx.getStorageSync('phone'),
            signature: api,
            id: This.data.id,
            type: This.data.type
        }, function (res) {
            console.log(res)
            This.setData({
                caller: res.list.caller,
                num: res.list.arrive.length + res.list.describe.length,
                describe: res.list.describe,
                arrive: res.list.arrive,
                yc: res.list.caller.type,
                level: res.level
            })
        })
    },
    //修改
    to_xiugai: function (e) {
        var This = this;
        wx.navigateTo({
            url: '../add_change/add_change?type=1' + '&id=' + e.currentTarget.dataset.id,
        })
    },
    //跳转维护
    to_weihu: function (e) {
        var This = this;
        console.log(e)
        wx.navigateTo({
            url: '../add_the_maintenance/add_the_maintenance?id=' + e.currentTarget.dataset.id + '&type=1',
        })
    },
    ycxs: function (e) {
        var This = this;
        console.log(e)
        if (e.currentTarget.dataset.type == 1) {
            var tr = 2
        } else {
            var tr = 1
        }
        var pack = {
            openid: wx.getStorageSync('openid'),
            phone: wx.getStorageSync('phone'),
            store_id: wx.getStorageSync('store_id'),
            type: tr,
            caller_id: e.currentTarget.dataset.id,
            token: API_Key,
        }
        var api = coding(pack);
        App._get('caller/callerTypeExit', {
            store_id: wx.getStorageSync('store_id'),
            openid: wx.getStorageSync('openid'),
            phone: wx.getStorageSync('phone'),
            signature: api,
            caller_id: e.currentTarget.dataset.id,
            type: tr
        }, function (res) {
            console.log(res)
            if (res.status == 1) {
                wx.showToast({
                    title: res.message,
                    duration: 2000
                })
                This.loade();
            } else {
                wx.showToast({
                    title: res.message,
                    duration: 2000
                })
            }
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        var This = this;
        This.loade();
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})